import React, { use } from "react";
import { Button, Checkbox, Form, Input } from "antd";
import style from '../login/index.module.css'
import request from '../../api/request'
import { useNavigate } from "react-router-dom";
import { useDispatch } from "react-redux";
import { username } from "../../store/user/index";
import { Tabs } from 'antd-mobile'
import { UserOutlined,UnlockOutlined,SafetyCertificateOutlined} from '@ant-design/icons';
import { Flex, Tooltip } from 'antd';
function Index() {
    const nav=useNavigate()
    const dispatch=useDispatch()
  const onFinish = (values) => {
    console.log("Success:", values);
  request.post('/login',values).then(res=>{
    alert('登录成功')
    nav('/home')
    localStorage.setItem('token',res.data.token)
    localStorage.setItem('username',res.data.username)
    dispatch(username(res.data))
  })
  };
  const onFinishFailed = (errorInfo) => {
    console.log("Failed:", errorInfo);
  };
  return (
    <div>
        <div className={style.login}>
            
        </div>
        <div className={style.op}>
   <Tabs>
          <Tabs.Tab title='登录' key='fruits'>
        <Form
          name="basic"
          labelCol={{ span: 8 }}
          wrapperCol={{ span: 16 }}
          style={{ maxWidth: 600 }}
          initialValues={{ remember: true }}
          onFinish={onFinish}
          onFinishFailed={onFinishFailed}
          autoComplete="off"
        >
          <Form.Item
            label="."
            name="account"
            rules={[{ required: true, message: "Please input your username!" }]}
          >
            <Input  prefix={<UserOutlined />}/>
          </Form.Item>

          <Form.Item
            label="."
            name="password"
            rules={[{ required: true, message: "Please input your password!" }]}
          >
           
            <Input.Password   prefix={ <UnlockOutlined />}/>
          </Form.Item>
           <Form.Item
      label="."
      name="username"
   
    >
     <div className={style.ok}>
  <Input placeholder="请输入验证码!"  prefix={<SafetyCertificateOutlined />}/><Button>获取验证码</Button>
     </div>
    
    </Form.Item>

          <Form.Item name="remember" valuePropName="checked" label={null}>  
            <Checkbox>记住我</Checkbox>
          </Form.Item>  

          <Form.Item label={null}>
            <Button type="primary" htmlType="submit" style={{width:'190px',background:'#fff',color:'#000',border:'1px solid #000'}}>
            登录
            </Button>
             <Button type="primary" htmlType="submit" style={{width:'190px',background:'blue',color:'#fff',border:'1px solid #000'}}>
           使用Gitee账号Star免费登录 
            </Button>
          </Form.Item>
          <div className={style.oc}>
            <span style={{marginLeft:'130px',color:'blue'}}>忘记密码?</span>
            <span style={{color:'blue'}}>手机登录</span>
          </div>
        </Form>
      
 
          </Tabs.Tab>
          <Tabs.Tab title='注册' key='vegetables'>
          西红柿
          </Tabs.Tab>
        </Tabs>
        </div>
      

    </div>
  );
}

export default Index;
